import requests
from tqdm import tqdm


token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3Mjc4MjQzNTIxLCJzdWIiOiI5MjYiLCJ0eXBlIjoiYWNjZXNzIn0.SyqgCGUJWFaAU9w0Pma2VdTPCW_as5WQm_YWeYJy4ns"


if __name__ == "__main__":
    with open("./clipIDs.txt", "r") as file:
        clip_ids = [line.strip() for line in file]

    paths = []
    for clip_id in tqdm(clip_ids, total=len(clip_ids)):
        url = f"https://zdrive-portal.mychery.com/portal/portal/api/v1/clips/details/{clip_id}?id={clip_id}"
        payload = {}
        headers = {"Authorization": token}
        response = requests.request("GET", url, headers=headers, data=payload)
        clip_response_json = response.json()
        clip_info = clip_response_json["data"]["clip"]
        storage_clip = clip_info["storage_clip"]

        flag = False
        if storage_clip["path"].startswith("/"):
            flag = True

        path = storage_clip["path"][1:] if flag else storage_clip["path"]
        paths.append(f"obs://{storage_clip['obs_bucket']}/{path}\n")

    with open("result.txt", "w") as f:
        f.writelines(paths)
